package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    // 扣库存
    @Override
    @Transactional
    public void deductStock(Long itemId, Long num) {
        //update().set("stock", byId.getStock() - num).eq("id", itemId).update();
        System.out.println("ok");
        try {
            update().setSql("stock = stock -" + num).eq("id", itemId).update();
        } catch (Exception e) {
            throw new RuntimeException("库存不足！");
        }
    }
}
